package fr.xebia.data;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

/**
 * 
 */
@Entity
@Table(name = "address")
public class Adresse implements Serializable {
	
	private static final long serialVersionUID = 1L;

	private Long id;
	private String city;
	private String street1;
	private String street2;
	private String zipcode;
	private Client client;

	/**
	 * Gets the id
	 * 
	 * @returns the id
	 */
	@Id
	//GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId() {
		return this.id;
	}

	/**
	 * Sets the id
	 * 
	 * @param the
	 *            id
	 */
	public void setId(Long pId) {
		this.id = pId;
	}

	/**
	 * Gets the city
	 * 
	 * @returns the city
	 */
	@Column(name = "CITY")
	public String getCity() {
		return this.city;
	}

	/**
	 * Sets the city
	 * 
	 * @param the
	 *            city
	 */
	public void setCity(String pCity) {
		this.city = pCity;
	}

	/**
	 * Gets the street1
	 * 
	 * @returns the street1
	 */
	@Column(name = "STREET1")
	public String getStreet1() {
		return this.street1;
	}

	/**
	 * Sets the street1
	 * 
	 * @param the
	 *            street1
	 */
	public void setStreet1(String pStreet1) {
		this.street1 = pStreet1;
	}

	/**
	 * Gets the street2
	 * 
	 * @returns the street2
	 */
	@Column(name = "STREET2")
	public String getStreet2() {
		return this.street2;
	}

	/**
	 * Sets the street2
	 * 
	 * @param the
	 *            street2
	 */
	public void setStreet2(String pStreet2) {
		this.street2 = pStreet2;
	}

	/**
	 * Gets the zipcode
	 * 
	 * @returns the zipcode
	 */
	@Column(name = "ZIPCODE")
	public String getZipcode() {
		return this.zipcode;
	}

	/**
	 * Sets the zipcode
	 * 
	 * @param the
	 *            zipcode
	 */
	public void setZipcode(String pZipcode) {
		this.zipcode = pZipcode;
	}

	/**
	 * Gets the list of Client
	 * 
	 * @returns the Client List
	 */
    @OneToOne
    //JoinColumn(name="adresse_id")
    @PrimaryKeyJoinColumn
    //OneToOne(mappedBy = "adresse")
	public Client getClient() {
		return this.client;
	}

	/**
	 * Sets the clients
	 * 
	 * @param the
	 *            clients
	 */
	public void setClient(Client client) {
		this.client = client;
	}

	@Override
	public boolean equals(Object obj) {
		Adresse otherAdresse = (Adresse) obj;
		EqualsBuilder equalsBuilder = new EqualsBuilder();
		equalsBuilder.append(getId(), otherAdresse.getId());
		equalsBuilder.append(getCity(), otherAdresse.getCity());
		equalsBuilder.append(getStreet1(), otherAdresse.getStreet1());
		equalsBuilder.append(getStreet2(), otherAdresse.getStreet2());
		equalsBuilder.append(getZipcode(), otherAdresse.getZipcode());
		return equalsBuilder.isEquals();
	}

	@Override
	public int hashCode() {
		HashCodeBuilder hashCodeBuilder = new HashCodeBuilder();
		hashCodeBuilder.append(getId());
		hashCodeBuilder.append(getCity());
		hashCodeBuilder.append(getStreet1());
		hashCodeBuilder.append(getStreet2());
		hashCodeBuilder.append(getZipcode());
		return hashCodeBuilder.toHashCode();
	}

	@Override
	public String toString() {
		StringBuffer buffer = new StringBuffer();
		// buffer.append("Adresse");
		// buffer.append('\n');
		buffer.append("id=").append(id).append(',');
		buffer.append("city=").append(city).append(',');
		buffer.append("street1=").append(street1).append(',');
		buffer.append("street2=").append(street2).append(',');
		buffer.append("zipcode=").append(zipcode).append(',');
		return buffer.toString();
	}
}
